import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.border.LineBorder;



public class UtilityLot extends Lot
{
	private int price;
	private int mortgageValue;
	private int ownedBy;	// determines which players owns the property
							// 0 - no owner, 1 - P1 owns, 2 - P2 owns, etc.
	
	// Dimensions:
	private int WIDTH;			// width of the property graphic
	private int HEIGHT;			// height of the property graphic

//	private ImageIcon imageElectric; // image used for the Electric Company logo on the lot
//	private ImageIcon imageWater; // image used for the Water Works logo on the lot
	private ImageIcon logo; // image used for logo on the lot
	
	private PropertyCardPanel pcp;
//	private boolean mouseFlag;
	
	public UtilityLot(String name, String type, String location)
	{
		super(name, type, location);
		price = 150;
		mortgageValue = 75;
		ownedBy = 0; // initially no one owns it
//		mouseFlag = false;
				
		if(location == "north")
		{
			WIDTH = 55;
			HEIGHT = 100;
		}
		else if(location == "west")
		{
			WIDTH = 100;
			HEIGHT = 55;
		}
		
		// sets the logo on the property on the game board
		setLogo();
		
		addMouseListener(new UtilityListener());
		pcp = new PropertyCardPanel();
		pcp.changeImage(name + ".jpg");
		pcp.setCostLabel(price);
		
		setPreferredSize(new Dimension(WIDTH, HEIGHT));
		setBorder(new LineBorder(Color.black));
		setBackground(new Color(200,222,186)); 
	} // end UtilityLot constructor
		
	public void setLogo()
	{
		// Creates a new ImageIcon from the name (String) of the property selected
		// and repaints??
		logo = new ImageIcon("./logos/" + name + "_small.jpg");		
		//repaint(); // not needed???
	}
	
	public int getPrice()
	{
		return price;
	} // end getPrice
	
	public int getMortgageValue()
	{
		return mortgageValue;
	} // end getMortgageValue
	
	public int getOwnedStatus()
	{
		return ownedBy;
	} // end getOwnedStatus
	
	// will actually draw the image:
	public void paintComponent(Graphics g)
	{	
		super.paintComponent(g);
		g.setColor(new Color(200,222,186));
		g.fillRect(1, 1, 55, 100);
		
		// draw black lines to make property borders thicker looking
		g.setColor(Color.black);
/*
		if(mouseFlag == false)
			g.setColor(Color.black);
		else if(mouseFlag == true)
			g.setColor(Color.white);
*/		
		if(location == "north")
		{
/*			if(mouseFlag == true)
			{
				g.fillRect(10, 10, 25, 35);
				g.drawLine(10, 0, 10, 100);
				g.drawLine(52, 0, 52, 100);
				g.drawLine(1, 0, 1, 100);
				g.drawLine(53, 0, 53, 100);
				g.drawLine(0, 1, 55, 1);
				g.drawLine(0, 2, 55, 2);
				g.drawLine(0, 97, 55, 97);
			}
*/			
			g.drawLine(1, 98, 55, 98);
			logo.paintIcon(this, g, 1, 0);
		}
		else if(location == "west")
		{
/*			if(mouseFlag == true)
			{
				g.drawLine(0, 5, 100, 5);
				g.drawLine(0, 4, 100, 4);
				g.drawLine(1, 0, 1, 55);
				g.drawLine(2, 0, 2, 55);
				g.drawLine(96, 0, 96, 55);
				g.drawLine(97, 0, 97, 55);
				g.drawLine(0, 52, 100, 52);
				g.drawLine(0 ,53, 100, 53);
			}
*/			
			g.drawLine(98, 0, 98, 55);
			logo.paintIcon(this, g, 0, 1);;
		}			
	} // end paintComponent
	
	private class UtilityListener implements MouseListener
	{
		public void mouseClicked(MouseEvent event)
		{			
			// open a frame with the PropertyCardPanel
			JFrame frame = new JFrame ("Utility Card");
			
			frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
			
//			JPanel j = new JPanel();
			
			// add the PropertyCardPanel to the frame
			frame.getContentPane().add(pcp);
			frame.pack();
			frame.setLocationRelativeTo(null);
			frame.setResizable(true);
			frame.setVisible(true);			
		}
		
		public void mousePressed(MouseEvent event){}
		public void mouseReleased(MouseEvent event){}
		public void mouseEntered(MouseEvent event)
		{
//			mouseFlag = true;
//			repaint();
		}
		public void mouseExited(MouseEvent event)
		{
//			mouseFlag = false;
//			repaint();
		}		
	} // end class UtilityListener
} // end class UtilityLot